<%@ page language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
                <%@include file="../../common/Include_input_head.jsp" %>

                <title></title>
        <script type="text/javascript">
        var left_index = 0;
        var right_index = 0;
        var size = parseInt('<s:property value="listApp.size()"/>');
        var appno = parseInt('<s:property value="appno"/>');
        $(document).ready(function () {
            //第一个二级菜单选中
            $("li[id='ulli_" + appno + "']").addClass("current");
            if ($.browser.mozilla || ($.browser.msie && $.browser.version > 8)) {
                setTimeout("showButtonList()", 500);
            } else {
                showButtonList();
            }

            //只读模式
            var url = location.href;
            var readOnly = false;
            if (url.indexOf("readOnlyPage") != -1) {
                var readOnlyPage_value_index = url.indexOf("readOnlyPage") + "readOnlyPage=".length;
                readOnly = url.substr(readOnlyPage_value_index, 4) == 'true';
            }
            if (readOnly) {
                $("li a[href*='appRoleSet-queryAllRole.action']").each(function (i) {
                    var href = $(this).attr("href");
                    $(this).attr("href", href + "&readOnlyPage=true");
                });
                $("div iframe[src*='appRoleSet-queryAllRole.action']").each(function (i) {
                    var href = $(this).attr("src");
                    $(this).attr("src", href + "&readOnlyPage=true");
                });
            }
        });

        /**
         * 调整权限菜单按钮格式
         * @memberOf {TypeName}
         */
        function showButtonList() {
            var buttons_width = '';
            $("li[id^='ulli_']").each(function (i) {
                if (i != 0) buttons_width += ';';
                buttons_width += i + ":" + $("#ulli_" + i).width() + ":" + $(this).find("span").html();
            });
            var width_document = document.body.clientWidth;
            var ws = buttons_width.split(";");
            var wis = 0;
            for (var i = 0; i < ws.length; i++) {
                var fontNum = parseInt(( ws[i].split(':')[2] ).length);
                wis += fontNum * 20;
                right_index = i;
                if (wis > width_document - 240) {
                    break;
                }
            }
            if (right_index < size) {
                for (var j = right_index + 1; j < size; j++) {
                    $("#ulli_" + j).hide();
                }
                $(".simpleTab_top").prepend("<li id='left_button' style='width:20px'><a onclick='javascript: trunleftorright(0)' target='frmrightChild' style='width:20px'>"
                        + "<span class='' style='width:16px;padding: 0 0 0 0;color:green'>《</span></a></li>");
                $(".simpleTab_top").append("<li id='right_button' style='width:20px'><a onclick='javascript: trunleftorright(1)' target='frmrightChild' style='width:20px'>"
                        + "<span class='' style='width:16px;padding: 0 0 0 0;color:green'>》</span></a></li>");
                $("#left_button span").addClass("icon_btn_left");
            }
            changeTurnButton();
        }
        //左右切换菜单
        function trunleftorright(obj) {
            if (obj == 0) {
                if (left_index != 0) {
                    left_index -= 1;
                    right_index -= 1;
                }
            } else {
                if (right_index != size - 1) {
                    left_index += 1;
                    right_index += 1;
                }
            }
            for (var i = 0; i < size; i++) {
                if (i < left_index || i > right_index) {
                    $("#ulli_" + i).hide();
                } else {
                    $("#ulli_" + i).show();
                }
            }
            var current_index = parseInt($("li[id^='ulli_'][class='current']").attr("id").substr(5));
            if (current_index < left_index || current_index > right_index) {
                $("li[id='ulli_" + current_index + "']").removeClass("current");
                $("li[id='ulli_" + left_index + "']").addClass("current");
                $("li[id='ulli_" + left_index + "'] a span").click();
            }
            changeTurnButton();
        }

        function changeTurnButton() {
            if (left_index != 0) {
                $("#left_button").show();
            } else {
                $("#left_button").hide();
            }
            if (right_index != size - 1) {
                $("#right_button").show();
            } else {
                $("#right_button").hide();
            }
        }

        function dataCheck(obj) {
            var roleid = document.getElementById("rolesId").value;
            var menuid = document.getElementById("menues").value;
            if (roleid == ',') {
                alert("请选择角色");
                return;
            } else {
                var roleid = roleid.split(",");
                if (roleid.length == 1) {
                    alert("请选择角色");
                    return;
                }
            }
            var workflows = "";
            $(":checkbox:checked[name='selectNodeMenu']",$("#frmrightChild")[0].contentWindow.document).each(function(){
                if(workflows != ""){workflows+=",";}
                workflows += $(this).val();
            })
            if(workflows == ""){
                alert("请选择功能名称");
                return;
            }
            document.getElementById("menues").value = workflows;
            var url = "./appRoleSet-list.action?flag=" + obj;
            document.forms[0].action = url;
            document.forms[0].submit();
        }
    </script>
</head>

<body style="text-align:center;">
<div id="scrollContent" style="overflow: hidden;">
    <s:form name="ysform" method="post" theme="simple">
        <s:hidden id="menues" name="menues"/>
        <s:hidden name="rolesId" id="rolesId"/>
        <s:hidden name="appid" id="appid"/>
        <s:hidden name="roles" id="roles"/>
        <div class="box1" panelWidth="100%">
            <table class="tableStyle" transMode="true" footer="normal">
                <tr>
                    <td align="left" width="100%" nowrap="nowrap" colspan="5">
                        <div class="box1" panelWidth="600" align="left">
                            <div class="simpleTab" iframeMode="true">
                                <ul class="simpleTab_top">
                                    <s:iterator value="listApp" status="stuts">
                                        <li id='ulli_<s:property value="%{#stuts.index}"/>'><a
                                                href="./appRoleSet-queryAllRole.action?appid=<s:property value='appid'/>"
                                                target="frmrightChild">
                                            <span><s:property value="appname"/> </span></a></li>
                                    </s:iterator>
                                </ul>
                                <div class="simpleTab_con">
                                    <IFRAME scrolling="no" width="100%" frameBorder=0 id=frmrightChild height=250px
                                            name=frmrightChild onload="iframeHeight('frmrightChild')"
                                            src="./appRoleSet-queryAllRole.action?appid=<s:property value='appid'/>&appno=<s:property value='appno'/> "
                                            allowTransparency="true"></IFRAME>
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
            </table>
            <div class="padding_top10">
                <table class="tableStyle" transMode="true">
                    <tr>
                        <td colspan="4">
                                <%--<input type="button" id="saveButton" value=" 增加资源 " onclick="dataCheck('save')"/>--%>
                            <input type="button" id="datecheckButton" value=" 保存 "
                                   title="此保存功能能主要用于初次为角色统一授权，后期权限变更，请针对角色单独调整" onclick="dataCheck('update')"/>

                            <div id="message">
                                <span style="color: #009"><s:property value="msg"/> </span>
                            </div>
                            <br/>
                            <label style="color:red">*</label><span style="line-height: 50px;">此保存功能能主要用于初次为角色授权，后期权限变更，请针对角色单独调整</span>
                            <label
                                    style="color:red">*</label>
                            <s:if test="actionErrors.size()>0 || actionMessages.size()>0 || fieldErrors.size()>0">
						<span id="SystemErrorMessage" style="top: 20px">
							<s:actionerror cssStyle="color:red"/>
							<s:actionmessage cssStyle="color:blue"/>
							<s:fielderror/>
						</span>
                            </s:if>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </s:form>
</div>
</body>
</html>
